﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using BruceCore.Models;
using NLog;
using BruceCore.Entity.Repositorys;
using BruceCore.Entity;
using BruceCore.Common.Helper;
using HeyCoder.AspNetCore.Mvc.Pager;
using HeyCoder.AspNetCore.Mvc.Pager.Interface;
using PlatformPay.BLL;

namespace BruceCore.Controllers
{
    public class HomeController : Controller
    {
        ILogger logger = LogManager.GetLogger(typeof(HomeController).Name);
        private ISysRoleRepository _roleRepository;
        public HomeController(ISysRoleRepository roleRepository)
        {
            _roleRepository = roleRepository;
        }

        public IActionResult Index()
        {
            //SysRole sysRole = new SysRole();
            //sysRole.ID = "20";
            //sysRole.SortNo = 1;
            //sysRole.RoleName = "普通会员";
            //sysRole.RoleLevel = 0;
            //sysRole.IsDel = 0;
            //sysRole.AddDate = DateTime.Now;
            //sysRole.UpdateDate = DateTime.Now;
            //sysRole.SysDefined = 1;
            //sysRole.IsAvailable = 1;
            //sysRole.HomePage = string.Empty;

            //_roleRepository.Add(sysRole);

            //string jsonstr = JsonHelper.SerializeObject(_roleRepository.GetById("0"));
            //logger.Log(LogLevel.Info, jsonstr);
            //logger.Log(LogLevel.Warn, "Index Warn");
            //logger.Log(LogLevel.Error, "Index Error");
            //logger.Log(LogLevel.Trace, "Index Trace");

            
            var sysRoleList = _roleRepository.List();
            if (Request.IsAjax())
            {
                return PartialView("UcRoleList", sysRoleList);
            }
            return View(sysRoleList);
        }

        public IActionResult About()
        {
            ViewData["Message"] = "Your application description page.";

            return View();
        }

        public IActionResult Contact()
        {
            ViewData["Message"] = "Your contact page.";

            return View();
        }

        public IActionResult Privacy()
        {
            return View();
        }

        [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
        public IActionResult Error()
        {
            return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
        }
    }
}
